package net.zjitc.utils;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by rj1502 on 2017/11/1.
 */
public class ClassUtils {

    public static List<Class> findAllClass(String scanPath) {
        List<Class> list = new ArrayList<>();
        String packName = scanPath.replace(".","/");
        URL path = Thread.currentThread().getContextClassLoader().getResource(packName);
        File file  = new File(path.getPath());
        File[] fileList = file.listFiles();
        for(File f : fileList){
            String className = f.getName().substring(0,f.getName().length()-6);

            Class clazz = null;
            try {
                clazz = Class.forName(scanPath+"."+className);
                list.add(clazz);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        return list;
    }
}
